package com.base;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.mvc.Controller;

import org.springframework.web.servlet.ModelAndView;


/**
 * 根据方法名注册不同的servlet
 * 实现在一个类文件中定义同一类操作的servlet
 * 
 */
@SuppressWarnings({ "serial", "unused" })
public class BaseController extends HttpServlet implements Controller {
	protected String methodName = null;
  
	public void setMethodName(String methodName)
	{
		this.methodName = methodName;
	}

	public void invokeMethod(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{
		Object objects[] = {request,response};
		Class<?> params[] = {HttpServletRequest.class,HttpServletResponse.class};
		Method method=this.getClass().getMethod(this.methodName, params);
		method.invoke(this, objects);
	}
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception
	{
		invokeMethod(request, response);
		return null;
	}



	
}
